package com.o2o.base;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.o2o.factory.CategoryFactory;
import com.o2o.factory.CategorySourceService;
import com.o2o.service.AreaService;
import com.o2o.service.TopicService;
import com.o2o.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;

public class BaseControllerAction extends ActionSupport implements SessionAware,ServletRequestAware,ServletResponseAware,Preparable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7136454145409817910L;
	protected HttpServletRequest request;
	protected HttpServletResponse response;
	protected Map<String,Object> session;
	protected Map<String,Object> result = new HashMap<String,Object>();
	protected String message;
	
	protected Logger logger = LoggerFactory.getLogger(this.getClass());
	
	protected CategorySourceService categorySourceService = null;
	
	
	@Resource
	protected
	UserService userService;
	
	@Resource
	protected
	AreaService areaService;
	
	protected
	@Resource 
	TopicService topicService;
	
	
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	public void setServletResponse(HttpServletResponse response) {
		this.response = response;
	}
	
	public void setServletRequest(HttpServletRequest request){
		this.request = request;
	}

	public Map<String, Object> getResult() {
		return result;
	}


	
	/**
	 * 得到CategoryFactory
	 */
	protected void getCategoryFactoryHandler(){
		categorySourceService = CategoryFactory.getCategoryFactory(session);
	}

	@Override
	public void prepare() throws Exception {
		//getCategoryFactoryHandler();
	}
	
	public String execute(){
		if (check()){
			return doExecute();
		}else{
			result.put("input_error", "输入参数错误");
			return "success";
		}
	}
	public boolean check(){
			return false;
	}
	public String doExecute(){
		return null;
	}

	
}
